<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <head>
        <title>Title</title>
        <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
        <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
        <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
        <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
    </head>
</head>
<body>
<br><br><br>
<button class="layui-btn" id="addShopClass" onclick="addImg()">添加轮播图</button>
<!--<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>-->

<div class="layui-form">
    <form class="layui-form" action="">
        <table class="layui-table">
            <thead>
            <tr>
                <th>图片</th>
                <th>序号</th>
                <th>时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach items="${slideShowList}" var="slideShow">
                <tr>
                    <td>${slideShow.path}</td>
                    <td>${slideShow.number}</td>
                    <td>${slideShow.createTime}</td>
                    <td>
                        <button type="button" class="layui-btn" onclick="update('${rl.id}');">修改</button>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <button type="button" class="layui-btn layui-btn-danger" onclick="delProduct('${rl.id}');">删除</button>
                    </td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </form>
</div>
<div id="under" style="margin-bottom: 5rem"></div>
</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        $(document).on('click','#add',function(){
            layer.open({
                type: 2,
                area: ['80%', '80%'],
                offset: '20px',
                shadeClose:true,
                content: '/shop/editCommodity?id=',
                end:function () {
                    console.log("页面要刷新");
                    window.location.reload();
                }
            });
        });
    });
    function update(id) {
        layer.open({
            type: 2,
            area: ['80%', '80%'],
            offset: '20px',
            shadeClose:true,
            content: '/shop/toShopClassInfo?id='+id,
            end:function () {
                console.log("页面要刷新");
                window.location.reload();
            }
        });
    }

    function delProduct(id) {
        $.ajax({
            url:'/shop/delClass',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:id,
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(dataA){
                console.log(dataA);
                if (dataA.code=='000000'){
                    window.location.reload();
                    // 获得frame索引
                }else {
                    layer.msg("删除失败",{time:1000,icon: 5});
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        })
    }
    /*二级分类*/
    function twoTypeList(id) {
        layer.open({
            type: 2,
            title:"二级分类",
            shadeClose:true,
            offset: '30px',
            area: ['75%', '75%'],
            content: '/shop/classTypeList?grade=1&id='+id,
            end:function () {
                window.location.reload();
            }
        });
    }



    /*添加商品*/
    function addImg() {
        //$.cookie("orgDate",null);
        layer.open({
            type: 2,
            title:"添加商户",
            shadeClose:true,
            offset: '30px',
            area: ['75%', '75%'],
            content: '/admin/shop/addshop.jsp',
            end:function () {
                window.location.reload();
            }
        });
    }
</script>

</body>
</html>
